package com.xiaofengstu.mcams.web.controller;


import com.xiaofengstu.mcams.annotation.ILog;
import com.xiaofengstu.mcams.dto.BasicResultDTO;
import com.xiaofengstu.mcams.dto.RoleDTO;
import com.xiaofengstu.mcams.enums.RespStatusEnum;
import com.xiaofengstu.mcams.web.entity.TRole;
import com.xiaofengstu.mcams.web.service.TRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fengzeng
 * @since 2022-05-07
 */
@RestController
@RequestMapping("/web/role")
@RequiredArgsConstructor
public class TRoleController {

  private final TRoleService roleService;


  @ILog("获取角色列表")
  @GetMapping("/list")
  public BasicResultDTO<List<TRole>> getRoleList() {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, roleService.getRoleListContainMenu());
  }

  @ILog("添加角色")
  @PostMapping()
  public BasicResultDTO<Boolean> addRole(@RequestBody TRole role) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, roleService.save(role));
  }

  @ILog("删除角色")
  @PostMapping("/del")
  public BasicResultDTO<Boolean> delById(@RequestBody Integer roleId) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, roleService.removeById(roleId));
  }

  @ILog("更新角色")
  @PostMapping("/update")
  public BasicResultDTO<Boolean> updateById(@RequestBody TRole role) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, roleService.updateById(role));
  }

  @ILog("获取角色的权限")
  @GetMapping("/getAuthId")
  public BasicResultDTO<List<String>> getAuthId(@RequestParam("roleId") Integer roleId) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, roleService.getAuthId(roleId));
  }

  @ILog("更新角色的权限")
  @PostMapping("/updateRights")
  public BasicResultDTO<Integer> updateRights(@RequestBody RoleDTO roleDTO) {

    return new BasicResultDTO<>(RespStatusEnum.SUCCESS,roleService.updateRights(roleDTO));
  }

}
